package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.EtiologyDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.EtiologyBase;
import com.itheima.service.EtiologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = EtiologyService.class)
@Transactional
public class EtiologyServiceImpl implements EtiologyService {
    @Autowired
    private EtiologyDao etiologyDao;


    @Override
    public void add(List<EtiologyBase> data) {
        for (EtiologyBase etiologyBase : data) {
            etiologyDao.add(etiologyBase);
        }
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();//查询条件
        //完成分页查询，基于mybatis框架提供的分页助手插件完成
        PageHelper.startPage(currentPage,pageSize);
        //select * from t_checkitem limit 0,10
        Page<EtiologyBase> page = etiologyDao.selectByCondition(queryString);
        long total = page.getTotal();
        List<EtiologyBase> rows = page.getResult();
        return new PageResult(total,rows);
    }
}
